package com.freewater.springboot.demo.ioc.beanpostprocessor.useannotation;

import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Autowired
    private BeanA beanA;

    @Override
    public Object postProcessBeforeInitialization(Object bean, @NotNull String beanName) throws BeansException {
        System.out.println("=====>> Bean '" + beanName + "' creating : " + bean.toString());
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, @NotNull String beanName) throws BeansException {
        System.out.println("=====>> Bean '" + beanName + "' created : " + bean.toString());
        return bean;
    }
}
